/*
 * RepeatInstructionDescription.java
 * 
 * last update: 24.01.2010 by Olaru Victor
 * 
 * author:	Victor(victor.olaru@gmail.com)
 * 
 * Obs:
 */

package engine;

@SuppressWarnings("serial")
class RepeatInstructionDescription extends InstructionDescription{
	ExpressionDescription ed;
	InstructionDescription id;

	RepeatInstructionDescription(int delaybefore, int line, NameSpaceDescription nsd,
			ExpressionDescription ed, InstructionDescription id){
		super(delaybefore, line, nsd);
		this.ed = ed;
		this.id = id;
	}

	DefaultInstruction instantiate(NameSpace ns)throws ParseException{

		Expression ex;
		try{
			ex = ed.instantiate(ns);
		}catch(ParseException exc){
			xConsole.dumpStack(exc);
			throw new ParseException(super.toString() + " error:" + exc);
		}

		return new RepeatInstruction(ns, delayBefore, this, ex,
				id.instantiate(ns), next == null ?  null : next.instantiate(ns));
	}

	public String toString(){
		return super.toString() + "repeat( " + ed + " )";
	}
}
